//
//  JWKTabBar.swift
//  Weibo
//
//  Created by 姜维克 on 16/5/19.
//  Copyright © 2016年 姜维克. All rights reserved.
//

import UIKit

class JWKTabBar: UITabBar {
    
    lazy var plusBtn : UIButton = {() -> UIButton in
        
        var plusBtn = UIButton()
        
        let width = UIScreenWidth/5
        
        plusBtn.frame = CGRectMake(2*width, 0, width, 49)
        
        plusBtn.setImage(UIImage(named:"tabbar_compose_icon_add"), forState: .Normal)
        
        plusBtn.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        
        plusBtn.setBackgroundImage(UIImage(named:"tabbar_compose_button"), forState: .Normal)
        
        plusBtn.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), forState: .Highlighted)
        
        
        return plusBtn
        
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //添加button
        addSubview(plusBtn)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        //布局子控件
        
        let width = UIScreenWidth/5
        
        var index : CGFloat = 0
        
        print(subviews.count)
        for subview in subviews{
            print(subview.classForCoder)
            
            if subview.isMemberOfClass(NSClassFromString("UITabBarButton")!) {
                
                let rect : CGRect = CGRectMake(index * width, 0, width, 49)
                
                
                subview.frame = rect
                
                
                index += (index == 1 ? 2 : 1)
                
            }
            
        }
        
    }
}
